USE [StoresManagement]
/****** Object:  StoredProcedure [dbo].[Users-Insert]    Script Date: [[20120714223943]] ******/
-- =============================================
-- Author:		Ahmed Fathi Hamouda Abd El Hafez
-- Create date: [[20120714223943]]
-- Description:	Insert record into table [dbo].[Users]
-- =============================================
SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO
/*IF EXISTS (SELECT * FROM dbo.Sysobjects where id = object_id(N'[dbo].[Users-Insert]') AND OBJECTPROPERTY(id, N'IsProcedure') = 1)
   drop procedure [dbo].[Users-Insert]*/
GO
-- =============================================
Create PROCEDURE [dbo].[Users-Insert]
	/*@User_RowNumber int =Null OUTPUT , 
	@User_ID uniqueidentifier =Null  , 
	@User_NameAr varchar(200) =Null  , 
	@User_NameEn varchar(200) =Null  , 
	@User_LoginName varchar(200) =Null  , 
	@User_Password varchar(100) =Null  , 
	@User_Email varchar(100) =Null  , 
	@User_Search varchar(max) =Null*/
AS
BEGIN
	--SET NOCOUNT ON added to prevent extra result sets from
	--interfering with SELECT statements.
	SET NOCOUNT ON;

	INSERT  INTO [dbo].[Users](/*[User_ID], [User_NameAr], [User_NameEn], [User_LoginName], [User_Password], [User_Email], [User_Search]*/)
	VALUES     (/*@User_ID, @User_NameAr, @User_NameEn, @User_LoginName, @User_Password, @User_Email, @User_Search*/)

	/*SELECT @User_RowNumber = [User_RowNumber]
    FROM [dbo].[Users]
    WHERE  ( [User_ID] =@User_ID )
	AND  ( [User_NameAr] =@User_NameAr )
	AND  ( [User_NameEn] =@User_NameEn )
	AND  ( [User_LoginName] =@User_LoginName )
	AND  ( [User_Password] =@User_Password )
	AND  ( [User_Email] =@User_Email )
	AND  ( [User_Search] =@User_Search )*/
END
GO
-- =============================================
USE [StoresManagement]
/****** Object:  StoredProcedure [dbo].[Users-update]    Script Date: [[20120714223943]] ******/
-- =============================================
-- Author:		Ahmed Fathi Hamouda Abd El Hafez
-- Create date: [[20120714223943]]
-- Description:	Update record in table [dbo].[Users]
-- =============================================
SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO
/*IF EXISTS (SELECT * FROM dbo.Sysobjects where id = object_id(N'[dbo].[Users-update]') AND OBJECTPROPERTY(id, N'IsProcedure') = 1)
   drop procedure [dbo].[Users-update]*/
GO
-- =============================================
Create PROCEDURE [dbo].[Users-update]
	/*@User_RowNumber int =Null OUTPUT , 
	@User_ID uniqueidentifier =Null  , 
	@User_NameAr varchar(200) =Null  , 
	@User_NameEn varchar(200) =Null  , 
	@User_LoginName varchar(200) =Null  , 
	@User_Password varchar(100) =Null  , 
	@User_Email varchar(100) =Null  , 
	@User_Search varchar(max) =Null*/
AS
BEGIN
	--SET NOCOUNT ON added to prevent extra result sets from
	--interfering with SELECT statements.
	SET NOCOUNT ON;

	/**/
		Update [dbo].[Users] SET 
		/*[User_ID] =@User_ID, 
		[User_NameAr] =@User_NameAr, 
		[User_NameEn] =@User_NameEn, 
		[User_LoginName] =@User_LoginName, 
		[User_Password] =@User_Password, 
		[User_Email] =@User_Email, 
		[User_Search] =@User_Search*/
		/*WHERE ([User_ID] = @User_ID)*/
	/**/

	/*SELECT @User_RowNumber = [User_RowNumber]
    FROM [dbo].[Users]
	WHERE ([User_ID] = @User_ID)*/
END
GO
-- =============================================
USE [StoresManagement]
/****** Object:  StoredProcedure [dbo].[Users-Insert-Update]    Script Date: [[20120714223943]] ******/
-- =============================================
-- Author:		Ahmed Fathi Hamouda Abd El Hafez
-- Create date: [[20120714223943]]
-- Description:	Insert OR Update record into table [dbo].[Users]
-- =============================================
SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO
/*IF EXISTS (SELECT * FROM dbo.Sysobjects where id = object_id(N'[dbo].[Users-Insert-Update]') AND OBJECTPROPERTY(id, N'IsProcedure') = 1)
   drop procedure [dbo].[Users-Insert-Update]*/
GO
-- =============================================
Create PROCEDURE [dbo].[Users-Insert-Update]
	/*@User_RowNumber int =Null OUTPUT , 
	@User_ID uniqueidentifier =Null  , 
	@User_NameAr varchar(200) =Null  , 
	@User_NameEn varchar(200) =Null  , 
	@User_LoginName varchar(200) =Null  , 
	@User_Password varchar(100) =Null  , 
	@User_Email varchar(100) =Null  , 
	@User_Search varchar(max) =Null  , 
	@Inserted bit OUTPUT*/ 
AS
BEGIN
	--SET NOCOUNT ON added to prevent extra result sets from
	--interfering with SELECT statements.
	SET NOCOUNT ON;
	IF NOT EXISTS (SELECT * FROM [dbo].[Users] 
					/*WHERE ([User_ID] = @User_ID)*/)
	BEGIN
		
		INSERT  INTO [dbo].[Users](/*[User_ID], [User_NameAr], [User_NameEn], [User_LoginName], [User_Password], [User_Email], [User_Search]*/)
		VALUES     (/*@User_ID, @User_NameAr, @User_NameEn, @User_LoginName, @User_Password, @User_Email, @User_Search*/)

		SET /*@*/Inserted=1
	END
	ELSE
	BEGIN
		
		/**/
			Update [dbo].[Users] SET 
			/*[User_ID] =@User_ID, 
			[User_NameAr] =@User_NameAr, 
			[User_NameEn] =@User_NameEn, 
			[User_LoginName] =@User_LoginName, 
			[User_Password] =@User_Password, 
			[User_Email] =@User_Email, 
			[User_Search] =@User_Search*/
			/*WHERE ([User_ID] = @User_ID)*/
		/**/
		
		SET /*@*/Inserted=0
	END

	/*SELECT @User_RowNumber = [User_RowNumber]
    FROM [dbo].[Users]
	WHERE ([User_ID] = @User_ID)*/
END
GO
-- =============================================
USE [StoresManagement]
/****** Object:  StoredProcedure [dbo].[Users-Delete]    Script Date: [[20120714223943]] ******/
-- =============================================
-- Author:		Ahmed Fathi Hamouda Abd El Hafez
-- Create date: [[20120714223943]]
-- Description:	delete records from table [dbo].[Users] based on optional Conditions
-- =============================================
SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO
/*IF EXISTS (SELECT * FROM dbo.Sysobjects where id = object_id(N'[dbo].[Users-Delete]') AND OBJECTPROPERTY(id, N'IsProcedure') = 1)
   drop procedure [dbo].[Users-Delete]*/
GO
-- =============================================
Create PROCEDURE [dbo].[Users-Delete]
	/*@User_RowNumber int =null  , 
	@User_ID uniqueidentifier =null  , 
	@User_NameAr varchar(200) =null  , 
	@User_NameEn varchar(200) =null  , 
	@User_LoginName varchar(200) =null  , 
	@User_Password varchar(100) =null  , 
	@User_Email varchar(100) =null  , 
	@User_Search varchar(max) =null*/
AS
BEGIN
	--SET NOCOUNT ON added to prevent extra result sets from
	--interfering with SELECT statements.
	SET NOCOUNT ON;

	Delete FROM  [dbo].[Users]
	WHERE /*( [User_RowNumber] = ISNULL(@User_RowNumber, [User_RowNumber]) )
	AND ( [User_ID] = ISNULL(@User_ID, [User_ID]) )
	AND ( [User_NameAr] like ISNULL(@User_NameAr, [User_NameAr]) )
	AND ( [User_NameEn] like ISNULL(@User_NameEn, [User_NameEn]) )
	AND ( [User_LoginName] like ISNULL(@User_LoginName, [User_LoginName]) )
	AND ( [User_Password] like ISNULL(@User_Password, [User_Password]) )
	AND ( [User_Email] like ISNULL(@User_Email, [User_Email]) )
	AND ( [User_Search] like ISNULL(@User_Search, [User_Search]) )*/
END
GO
-- =============================================
USE [StoresManagement]
/****** Object:  StoredProcedure [dbo].[Users-Select]    Script Date: [[20120714223943]] ******/
-- =============================================
-- Author:		Ahmed Fathi Hamouda Abd El Hafez
-- Create date: [[20120714223943]]
-- Description:	select records from table [dbo].[Users] based on optional Conditions
-- =============================================
SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO
/*IF EXISTS (SELECT * FROM dbo.Sysobjects where id = object_id(N'[dbo].[Users-Select]') AND OBJECTPROPERTY(id, N'IsProcedure') = 1)
   drop procedure [dbo].[Users-Select]*/
GO
-- =============================================
Create PROCEDURE [dbo].[Users-Select]
	/*@User_RowNumber int =null  , 
	@User_ID uniqueidentifier =null  , 
	@User_NameAr varchar(200) =null  , 
	@User_NameEn varchar(200) =null  , 
	@User_LoginName varchar(200) =null  , 
	@User_Password varchar(100) =null  , 
	@User_Email varchar(100) =null  , 
	@User_Search varchar(max) =null*/
AS
BEGIN
	--SET NOCOUNT ON added to prevent extra result sets from
	--interfering with SELECT statements.
	SET NOCOUNT ON;

	SELECT * FROM  [dbo].[Users]
	WHERE /*( [User_RowNumber] = ISNULL(@User_RowNumber, [User_RowNumber]) )
	AND ( [User_ID] = ISNULL(@User_ID, [User_ID]) )
	AND ( [User_NameAr] like ISNULL(@User_NameAr, [User_NameAr]) )
	AND ( [User_NameEn] like ISNULL(@User_NameEn, [User_NameEn]) )
	AND ( [User_LoginName] like ISNULL(@User_LoginName, [User_LoginName]) )
	AND ( [User_Password] like ISNULL(@User_Password, [User_Password]) )
	AND ( [User_Email] like ISNULL(@User_Email, [User_Email]) )
	AND ( [User_Search] like ISNULL(@User_Search, [User_Search]) )*/
END
GO
-- =============================================
